package cn.hrlly.tao2shou.presenter;

import android.content.Context;

import cn.hrlly.tao2shou.biz.PublishCommoditiesListBiz;
import cn.hrlly.tao2shou.biz.PublishCommoditiesListBizImpl;
import cn.hrlly.tao2shou.domain.CommodityList;
import cn.hrlly.tao2shou.listener.OnPublishCommoditiesListListener;
import cn.hrlly.tao2shou.view.view_interface.PublishCommoditiesListView;

/**
 * User: gengliang
 * Date: 2016-01-28
 * Time: 14:46
 */

public class PublishCommoditiesListPresenterImpl implements OnPublishCommoditiesListListener,PublishCommoditiesListPresenter {

    private PublishCommoditiesListBiz publishCommoditiesListBiz;
    private PublishCommoditiesListView publishCommoditiesListView;

    public PublishCommoditiesListPresenterImpl(PublishCommoditiesListView publishCommoditiesListView,Context context){
        this.publishCommoditiesListBiz=new PublishCommoditiesListBizImpl(this,context);
        this.publishCommoditiesListView=publishCommoditiesListView;
    }
    //使用联网的方式显示
    @Override
    public void showPublishCommodities() {
        publishCommoditiesListBiz.publishCommoditiesList();
    }

    //使用缓存显示
    @Override
    public void showCachePublishCommodities() {
        CommodityList commodityList=publishCommoditiesListBiz.getCachePublishCommoditiesList();
        if(commodityList!=null)
            publishCommoditiesListView.showListView(commodityList);
    }

    @Override
    public void showPublishCommoditiesSucc(CommodityList commodityList) {
        publishCommoditiesListView.showListView(commodityList);
        //将发布商品列表缓存
        publishCommoditiesListBiz.saveCachePublishCommoditiesList(commodityList);
    }

    @Override
    public void showPublishCommoditiesFail(int errorMessage) {
        publishCommoditiesListView.showMessage(errorMessage);
    }

    @Override
    public void showPublishCommoditiesFail(String errorMessage) {
        publishCommoditiesListView.showMessage(errorMessage);
    }
}
